﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace CXMLStudioIDE.DataAccessLayer
{
    public class DataDictionaryDAL : CXMLStudioDAL
    {
        public DataSet SaveBusinessEntityDefinitionInContext(int int_ContextID, int int_EntityID, string txt_BusinessDefinition)
        {
            DataSet DS = new DataSet();
            System.Data.SqlClient.SqlConnection con = GetConnection();
            System.Data.SqlClient.SqlDataAdapter da = new SqlDataAdapter("dbo.SaveBusinessEntityDefinitionInContext", con);
            da.SelectCommand.CommandType = CommandType.StoredProcedure;
            da.SelectCommand.Parameters.AddWithValue("int_ContextID", int_ContextID);
            da.SelectCommand.Parameters.AddWithValue("int_EntityID", int_EntityID);
            da.SelectCommand.Parameters.AddWithValue("txt_BusinessDefinition", txt_BusinessDefinition);
            con.Open();
            da.Fill(DS);
            da.Dispose();
            con.Close();
            return DS;
        }

        public DataSet SaveComment(string txt_Comment, int int_CXMLUserID, Int32 int_ContextualDefinitionID,
                int int_BusinessDefinitionID, int int_EntityTypeVersionsDefinitionID)
        {
            DataSet DS = new DataSet();
            System.Data.SqlClient.SqlConnection con = GetConnection();
            System.Data.SqlClient.SqlDataAdapter da = new SqlDataAdapter("dbo.SaveComment", con);
            da.SelectCommand.CommandType = CommandType.StoredProcedure;
            da.SelectCommand.Parameters.AddWithValue("txt_Comment", txt_Comment);
            da.SelectCommand.Parameters.AddWithValue("int_CXMLUserID", int_CXMLUserID);
            if (int_ContextualDefinitionID >= 0)
                da.SelectCommand.Parameters.AddWithValue("int_ContextualDefinitionID", int_ContextualDefinitionID);
            else
                da.SelectCommand.Parameters.AddWithValue("int_ContextualDefinitionID", DBNull.Value);
            if (int_BusinessDefinitionID >= 0)
                da.SelectCommand.Parameters.AddWithValue("int_BusinessDefinitionID", int_BusinessDefinitionID);
            else
                da.SelectCommand.Parameters.AddWithValue("int_BusinessDefinitionID", DBNull.Value);
            if (int_EntityTypeVersionsDefinitionID >= 0)
                da.SelectCommand.Parameters.AddWithValue("int_EntityTypeVersionsDefinitionID", int_EntityTypeVersionsDefinitionID);
            else
                da.SelectCommand.Parameters.AddWithValue("int_EntityTypeVersionsDefinitionID", DBNull.Value);
            con.Open();
            da.Fill(DS);
            da.Dispose();
            con.Close();
            return DS;
        }
    }
}
